// 用户管理模块的接口
import request from "@/utils/request";
import { AssignRoleObj, RoleResData, UserObj, UserResData } from "./types";

enum API {
    // 获取用户账号信息接口
    GETUSERLIST_URL = '/admin/acl/user/',
    // 添加用户账号信息接口
    ADDUSER_URL = '/admin/acl/user/save',
    // 修改用户账号信息接口
    UPDATEUSER_URL = '/admin/acl/user/update',
    // 获取角色信息接口
    ALLORHASROLES_URL = '/admin/acl/user/toAssign/',
    // 给用户分配已选择角色
    ASSIGNROLE_URL = '/admin/acl/user/doAssignRole',
    // 删除用户的接口
    DELETEUSER_URL = '/admin/acl/user/remove/',
    // 批量删除用户的接口
    BATCHDELETEUSER_URL = '/admin/acl/user/batchRemove',
}

// 获取用户账号信息及根据输入框内容搜索对应的用户
export const reqUserList = (page: number, limit: number, username: string): Promise<UserResData> => request({
    url: API.GETUSERLIST_URL + `${page}/${limit}`,
    method: 'GET',
    params: {
        username
    }
})
// 添加用户账号信息
export const reqAddUser = (data: UserObj): any => request({
    url: API.ADDUSER_URL,
    method: 'POST',
    data
})
// 修改用户账号信息
export const reqEditUser = (data: UserObj): any => request({
    url: API.UPDATEUSER_URL,
    method: 'PUT',
    data
})
// 获取所有角色及已分配角色信息
export const reqAllOrHasRoles = (userId: number): Promise<RoleResData> => request({
    url: API.ALLORHASROLES_URL + userId,
    method: 'GET'
})
// 给用户分配已选择角色
export const reqAssignRole = (data: AssignRoleObj): any => request({
    url: API.ASSIGNROLE_URL,
    method: 'POST',
    data
})
// 删除某个用户信息
export const reqDeleteUser = (userId: number): any => request({
    url: API.DELETEUSER_URL + userId,
    method: 'DELETE'
})
// 批量删除某个用户信息
export const reqBatchDeleteUser = (userIds: number[]): any => request({
    url: API.BATCHDELETEUSER_URL,
    method: 'DELETE',
    // 直接携带数组数据，不需要对象包裹
    data: userIds
})